package kr.hkit.powerjava.chapter17.work;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BoxLayout;

public class RadiobtnTest03 extends JPanel implements ActionListener {
	private JRadioButton small, medium, large;
	private JLabel text;
	private JPanel topPanel, sizePanel, resultpPanel;
	public RadiobtnTest03() {
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		topPanel = new JPanel();
		JLabel lbl = new JLabel("어떤 크기의 커피를 주문하시겠습니까?");
		topPanel.add(lbl);
		add(topPanel);
		
		sizePanel = new JPanel();
		small = new JRadioButton("Small Size");
		medium = new JRadioButton("Medium Size");
		large = new JRadioButton("Large Size");
		
		ButtonGroup size = new ButtonGroup();
		size.add(small);
		size.add(medium);
		size.add(large);
		
		small.addActionListener(this);
		medium.addActionListener(this);
		large.addActionListener(this);
		
		sizePanel.add(small);
		sizePanel.add(medium);
		sizePanel.add(large);
		add(sizePanel);
		
		resultpPanel = new JPanel();
		text = new JLabel("크기가 선택되지 않았습니다.");
		text.setForeground(Color.red);
		resultpPanel.add(text);
		
		add(resultpPanel);
		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == small){
			text.setText("Small 크기가 선택되었습니다.");
		}else if(e.getSource() == medium){
			text.setText("Medium 크기가 선택되었습니다.");
		}else{
			text.setText("Large 크기가 선택되었습니다.");
		}
	}

}
